﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.Products
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int ProductId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(ProductId);
				}
			}
		}
			
	private void ShowInfo(int ProductId)
	{
		Maticsoft.BLL.Products bll=new Maticsoft.BLL.Products();
		Maticsoft.Model.Products model=bll.GetModel(ProductId);
		this.lblProductId.Text=model.ProductId.ToString();
		this.txtProductName.Text=model.ProductName;
		this.txtProductType.Text=model.ProductType;
		this.txtDescription.Text=model.Description;
		this.txtInterestRate.Text=model.InterestRate;
		this.txtStartDate.Text=model.StartDate;
		this.txtEndDate.Text=model.EndDate;
		this.txtMinimumInvestment.Text=model.MinimumInvestment.ToString();
		this.txtMaximumInvestment.Text=model.MaximumInvestment.ToString();
		this.txtCurrentValue.Text=model.CurrentValue.ToString();
		this.txtInvestmentReturn.Text=model.InvestmentReturn.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtProductName.Text.Trim().Length==0)
			{
				strErr+="产品名称不能为空！\\n";	
			}
			if(this.txtProductType.Text.Trim().Length==0)
			{
				strErr+="产品类型不能为空！\\n";	
			}
			if(this.txtDescription.Text.Trim().Length==0)
			{
				strErr+="产品描述不能为空！\\n";	
			}
			if(this.txtInterestRate.Text.Trim().Length==0)
			{
				strErr+="利率不能为空！\\n";	
			}
			if(this.txtStartDate.Text.Trim().Length==0)
			{
				strErr+="开始日期不能为空！\\n";	
			}
			if(this.txtEndDate.Text.Trim().Length==0)
			{
				strErr+="结束日期不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtMinimumInvestment.Text))
			{
				strErr+="最低投资额格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtMaximumInvestment.Text))
			{
				strErr+="最高投资额格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtCurrentValue.Text))
			{
				strErr+="当前价值格式错误！\\n";	
			}
			if(!PageValidate.IsDecimal(txtInvestmentReturn.Text))
			{
				strErr+="投资回报格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int ProductId=int.Parse(this.lblProductId.Text);
			string ProductName=this.txtProductName.Text;
			string ProductType=this.txtProductType.Text;
			string Description=this.txtDescription.Text;
			string InterestRate=this.txtInterestRate.Text;
			string StartDate=this.txtStartDate.Text;
			string EndDate=this.txtEndDate.Text;
			decimal MinimumInvestment=decimal.Parse(this.txtMinimumInvestment.Text);
			decimal MaximumInvestment=decimal.Parse(this.txtMaximumInvestment.Text);
			decimal CurrentValue=decimal.Parse(this.txtCurrentValue.Text);
			decimal InvestmentReturn=decimal.Parse(this.txtInvestmentReturn.Text);


			Maticsoft.Model.Products model=new Maticsoft.Model.Products();
			model.ProductId=ProductId;
			model.ProductName=ProductName;
			model.ProductType=ProductType;
			model.Description=Description;
			model.InterestRate=InterestRate;
			model.StartDate=StartDate;
			model.EndDate=EndDate;
			model.MinimumInvestment=MinimumInvestment;
			model.MaximumInvestment=MaximumInvestment;
			model.CurrentValue=CurrentValue;
			model.InvestmentReturn=InvestmentReturn;

			Maticsoft.BLL.Products bll=new Maticsoft.BLL.Products();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
